package com.naizhuai.ui.components.listener;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.PopupWindow;
import android.widget.TextView;

/**
 *
 * Created by code_han on 2018/3/27.
 */

public class PopUpWindowMissListener implements PopupWindow.OnDismissListener {

    private TextView tvView;
    private int resource;
    private Context mContext;

    public PopUpWindowMissListener(TextView tvView, int resource,Context mContext) {
        this.tvView = tvView;
        this.resource = resource;
        this.mContext=mContext;
    }

    @Override
    public void onDismiss() {
        setTextImage(tvView, resource);
    }

    /**
     * 给TextView右边设置图片
     *
     * @param resId
     */
    private void setTextImage(TextView textView, int resId) {
        Drawable drawable = mContext.getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());// 必须设置图片大小，否则不显示
        textView.setCompoundDrawables(null, null, drawable, null);
    }
}
